﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using eWallet.Data.Local;

namespace WPFTestArena
{
	/// <summary>
	/// Interaction logic for SecretsWindow.xaml
	/// </summary>
	public partial class SecretsWindow : Window
	{
		public SecretsWindow()
		{
			InitializeComponent();

			this.PopulateDataSource();
			this.SecretsList.DataSource = this.DataSet;
		}


		private eWalletDataSet DataSet = new eWalletDataSet();


		protected override void OnClosed(EventArgs e)
		{
			this.DataSet.Dispose();
			base.OnClosed(e);
		}


		private void PopulateDataSource()
		{
			this.DataSet.Blobs.Clear();
			this.DataSet.Groups.Clear();
			this.DataSet.Secrets.Clear();
			this.DataSet.SecretsTags.Clear();
			this.DataSet.Tags.Clear();

			this.DataSet.Blobs.AddBlobsRow(Guid.NewGuid(), new byte[1]);

			this.DataSet.Groups.AddGroupsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", "Default", null, eWallet.Security.Cryptography.EncryptionMethod.Password, this.DataSet.Blobs[0], null);

			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 1", "text/plain", null, this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 2", "text/plain", null, this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 3", "text/plain", null, this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 4", "text/plain", null, this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 5", "application/pdf", "document.pdf", this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "A veeeeery looooong description for this otherwise meaningless secret, that actually is no secret at all, it is just a place holder so that we get some 'stuffing' to this list of secrets.", "text/plain", null, this.DataSet.Blobs[0]);
			this.DataSet.Secrets.AddSecretsRow(Guid.NewGuid(), DateTime.UtcNow, "Administrator", this.DataSet.Groups[0], "Secret 7", "application/ms-word", "cv.doc", this.DataSet.Blobs[0]);

			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "adminaccount");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "codeplex.com");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "google.com");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "live.com");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "password");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "serviceaccount");
			this.DataSet.Tags.AddTagsRow(Guid.NewGuid(), "username");
			
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[0], this.DataSet.Tags[0]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[0], this.DataSet.Tags[1]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[0], this.DataSet.Tags[5]);

			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[1], this.DataSet.Tags[1]);

			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[2], this.DataSet.Tags[2]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[2], this.DataSet.Tags[1]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[2], this.DataSet.Tags[5]);
			
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[3], this.DataSet.Tags[3]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[3], this.DataSet.Tags[1]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[3], this.DataSet.Tags[5]);

			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[4], this.DataSet.Tags[4]);
			
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[5], this.DataSet.Tags[5]);
			
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[6], this.DataSet.Tags[6]);
			this.DataSet.SecretsTags.AddSecretsTagsRow(this.DataSet.Secrets[6], this.DataSet.Tags[5]);


		}

	}
}
